//
//  FirCirVoiceTipsView.m
//  tcpoctest
//
//  Created by apple on 13-7-16.
//  Copyright (c) 2013年 gump. All rights reserved.
//

#import "FirCirVoiceTipsView.h"
#import <QuartzCore/QuartzCore.h>
#import "AppDelegate.h"


@implementation FirCirVoiceTipsView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        tipsBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 184, 184)];
        tipsBackView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
        tipsBackView.layer.cornerRadius = 10;
        tipsBackView.clipsToBounds = YES;
        [self addSubview:tipsBackView];
        
        voiceStateImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ptt_tip_start.png"]];
        voiceStateImageView.center = CGPointMake(184 / 2.0, 184 / 2.0 - 20);
        [tipsBackView addSubview:voiceStateImageView];
        
        tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 159 - 20, 184, 46)];
        tipsLabel.backgroundColor = [UIColor clearColor];
        tipsLabel.textAlignment = UITextAlignmentCenter;
        tipsLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
        tipsLabel.textColor = [UIColor whiteColor];
        tipsLabel.font = [UIFont boldSystemFontOfSize:24];
        tipsLabel.adjustsFontSizeToFitWidth = YES;
        [tipsBackView addSubview:tipsLabel];
    }
    return self;
}

- (void)showPttFailImage
{
    tipsLabel.text = @"时间太短";
    voiceStateImageView.image = [UIImage imageNamed:@"ptt_tips_fail.png"];
}

- (void)showPttStartImage
{
    tipsLabel.text = @"请说话";
    voiceStateImageView.image = [UIImage imageNamed:@"ptt_tip_start.png"];
    AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [appDelegate.window addSubview:self];
}

- (void)updatePttSoundVolumImage:(int)soundLevel
{
    tipsLabel.text = @"录音中";
    NSString *imageName =  [NSString stringWithFormat:@"ptt_sound_volum_%d.png",soundLevel];
    voiceStateImageView.image = [UIImage imageNamed:imageName];
}

- (void)dismissTips
{
    [self removeFromSuperview];
}

- (void)showPttStartImageBySuperView:(UIView *)superview
{
    if (superview == nil) {
        return;
    }
    
    tipsLabel.text = @"请说话";
    voiceStateImageView.image = [UIImage imageNamed:@"ptt_tip_start.png"];
    [superview addSubview:self];
}

@end
